package logic

import (
	"context"
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"
	"doctor-medicine-system/models/mysql"
	"errors"
	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserAddLogic) UserAdd(in *doctorrpc.UserAddRequest) (*doctorrpc.UserAddResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{
		//Model:    gorm.Model{},
		Mobile:   in.Mobile,
		Password: in.Password,
	}

	err := user.UserAddBy(mysql.DB)
	if err != nil {
		return nil, errors.New("入录失败")
	}

	return &doctorrpc.UserAddResponse{
		UserId: int64(user.ID),
	}, nil
}
